
from native.common.file_selector import FileSelector


class ExcelFileSelector(FileSelector):
    def __init__(self, root, title, x, y, w, h):
        super().__init__(root, title, self.after_on_selected, None)

        self.__x = x
        self.__y = y
        self.__w = w
        self.__h = h

        self.on_load()
        
    def x(self):
        return self.__x
    def y(self):
        return self.__y
    def set_x(self, value):
        if value != self.__x:
            self.__x = value
        return self
    def set_y(self, value):
        if value != self.__y:
            self.__y = value
        return self
    def height(self):
        return self.__h
    def width(self):
        return self.__w

    def on_load(self):
        super(ExcelFileSelector, self).on_load()

        super(ExcelFileSelector, self).insert_file_types(0, "excel", "*.xlsx")
        super(ExcelFileSelector, self).insert_file_types(1, "old excel", "*.xls")
        
        entry_width = 350
        button_width = 30

        self._label.place(x=self.__x, y=self.__y, width=self.__w - entry_width - button_width, height=self.__h)
        self._entry.place(x=self.__w + self.__x - entry_width - button_width, y=self.__y, width=entry_width,  height=self.__h)
        self._button.place(x=self.__w + self.__x - button_width, y=self.__y,width=button_width, height=self.__h)

        self._entry["borderwidth"] = "1px"

        self._button["bg"] = "#efefef"
        self._button["text"] = "..."


    def on_selected_ok(self, file_path):
        print(f"{file_path}")

    def after_on_selected(self, file_path):
        print(f"after_on_selected:{file_path}")
